/*
 * FLine: 线
 *
 * 历史:
 *    2019-12-17 姚彧 创建
 */

#ifndef _FLINE_H_
#define _FLINE_H_

#ifndef BriEPS
#define BriEPS 0.00001
#endif

#include "FVector.h"
#include <cmath>

namespace yy {
namespace geometry{

using namespace yy::math;

template<int n, class Real>
struct FLine
{
    typedef FVector<n,Real> VectorN;
    VectorN origin, direction;
    
    FLine(){}
    
    FLine(Real x0, Real y0, Real dx, Real dy){
        origin.x()=x0;
        origin.y()=y0;
        direction.x()=dx;
        direction.y()=dy;
    }
    
    FLine(VectorN const& o, VectorN const& d)
        :origin(o), direction(d)
    {
    }
};

template<class Real>
FLine<2,Real> line2d_from_xyk(Real x0, Real y0, Real k)
{
    return FLine<2,Real>(x0, y0, (Real)1, k);
}

template<class Real>
FLine<2,Real> line2d_from_abc(Real a, Real b, Real c)
{
    assert(abs(a) > BriEPS || abs(b) > BriEPS);
    if (b != (Real)0)
    {
        return FLine<2,Real>(0, -c / b, 1, -a / b);
    }
    else
    {
        return FLine<2,Real>(-c / a, 0, 0, 1);
    }
}

}
}


#endif /* _FLINE_H_ */
